package cn.edu.scau.cmi.yangmupei.client;

import java.util.List;
import java.util.Scanner;

import cn.edu.scau.cmi.yangmupei.dao.StudentDAO;
import cn.edu.scau.cmi.yangmupei.dao.TeacherDAO;
import cn.edu.scau.cmi.yangmupei.domain.Student;
import cn.edu.scau.cmi.yangmupei.domain.Teacher;

public class TestDemo {

	public static void main(String[] args) {
		StudentDAO stdao = new StudentDAO();
		TeacherDAO teadao = new TeacherDAO();
		Student student = new Student();
		Teacher teacher = new Teacher();
		Scanner input = new Scanner(System.in);
		int n;
		int number;
		String name;
		Student stu = new Student();
		while(true) {
			System.out.println("**************");
			System.out.println("*1.添加学生       2.修改学生");
			System.out.println("*3.删除学生       4.添加教师");
			System.out.println("*5.修改教师       6.删除教师");
			System.out.println("*7.学生选择指导老师 ");
			System.out.println("*8.学生修改指导老师 ");
			System.out.println("*9.老师选择指导被指导学生 ");
			System.out.println("*10.老师修改指导被指导学生 ");

			
			System.out.println("请输入您的选项：");
			n = input.nextInt();
			switch(n) {
				case 1:
					System.out.println("请输入学生名字");
					name = input.next();
					stu.setName(name);
					System.out.println("请输入学生学号");
					number = input.nextInt();
					stu.setId(number);
					stu.setTutor(0);
					stdao.save(stu);
					break;
				case 2:
					System.out.println("请输入要修改的学生的学号");
					number = input.nextInt();
					stu.setId(number);
					System.out.println("要将名字修改为：");
					name = input.next();
					stu.setName(name);
					stdao.merge(stu);
					break;
				case 3:
					System.out.println("请输入学生名字");
					name = input.next();
					stu.setName(name);
					System.out.println("请输入学生学号");
					number = input.nextInt();
					stu.setId(number);
					stdao.delete(stu);
					break;
				case 4:
					System.out.println("请输入老师名字");
					name = input.next();
					teacher.setName(name);
					System.out.println("请输入老师工号");
					number = input.nextInt();
					teacher.setId(number);
					teadao.save(teacher);
					break;
				case 5:
					System.out.println("请输入要修改的老师的工号");
					number = input.nextInt();
					teacher.setId(number);
					System.out.println("要将名字修改为：");
					name = input.next();
					teacher.setName(name);
					teadao.merge(teacher);
					break;
				case 6:
					System.out.println("请输入要删除的老师名字");
					name = input.next();
					teacher.setName(name);
					System.out.println("请输入要删除的老师工号");
					number = input.nextInt();
					teacher.setId(number);
					teadao.delete(teacher);
					break;
				case 7:
					System.out.println("请输入学生学号");
					number = input.nextInt();
					stu = stdao.findById(number);
					System.out.println("该学生名字为"+stu.getName());
					System.out.println("请选择指导老师的工号");
					number = input.nextInt();
					stu.setTutor(number);
					stdao.merge(stu);
					break;
				case 8:
					System.out.println("请输入学生学号");
					number = input.nextInt();
					stu = stdao.findById(number);
					teacher = teadao.findById(stu.getTutor());
					System.out.println("该学生名字为:"+stu.getName()+"指导老师的工号:"+teacher.getId()+"名字为："+teacher.getName());
					System.out.println("请修改指导老师的工号为：");
					number = input.nextInt();
					stu.setTutor(number);
					stdao.merge(stu);
					
					break;
				case 9:
					System.out.println("请输入老师的工号");
					number = input.nextInt();
					teacher = teadao.findById(number);
					System.out.println("该老师的名字为："+teacher.getName());
					List<Student> students1 = stdao.findByName(number);
					System.out.println("指导学生有：");
					for (int i = 0; i < students1.size(); i++) {
						System.out.println(students1.get(i).getId()+":"+students1.get(i).getName());
					}
					System.out.println("输入要添加指导的学生的id：");
					number = input.nextInt();
					stu = stdao.findById(number);
					stu.setTutor(teacher.getId());
					stdao.merge(stu);
					break;
					
				case 10:
					System.out.println("请输入老师的工号");
					number = input.nextInt();
					teacher = teadao.findById(number);
					System.out.println("该老师的名字为："+teacher.getName());
					List<Student> students = stdao.findByName(number);
					System.out.println("指导学生有：");
					for (int i = 0; i < students.size(); i++) {
						System.out.println(students.get(i).getId()+":"+students.get(i).getName());
					}
					System.out.println("输入要删除的学生的id：");
					number = input.nextInt();
					stu = stdao.findById(number);
					stu.setTutor(0);
					stdao.merge(stu);
					break;
					
			}
//			
		}

	
	}
}
